﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using Medical_Store_Billing.Component;
using System.Windows.Forms;
using Medical_Store_Billing.Object_Class;

namespace Medical_Store_Billing.Data_Access_Layer
{
    class NhacungcapDAL
    {
        Dataservice m_nhacungcap = new Dataservice();
        public DataTable Laydsnhacungcap()
        {
            SqlCommand cmd = new SqlCommand("Select * from nhacungcap");
            m_nhacungcap.Load(cmd);
            return m_nhacungcap;
        }
       
        public DataTable Timncc(string mancc)
        {
            SqlCommand cmd = new SqlCommand("Select * from nhacungcap where mancc like N'%" + mancc + "%'");
            m_nhacungcap.Load(cmd);
            return m_nhacungcap;
        }
        public bool Themncc(Nhacungcapclass m_ncc)
        {
            SqlCommand cmd = new SqlCommand("Insert into nhacungcap values(@mancc,@tenncc,@dienthoai,@diachi)");
            cmd.Parameters.Add("mancc", SqlDbType.VarChar).Value = m_ncc.Mancc;
            cmd.Parameters.Add("tenncc", SqlDbType.NVarChar).Value = m_ncc.Tenncc;
            cmd.Parameters.Add("dienthoai", SqlDbType.Float).Value = m_ncc.Dienthoai;
            cmd.Parameters.Add("diachi", SqlDbType.Text).Value = m_ncc.Diachi;
          
            if (m_nhacungcap.ExecuteNonQuery(cmd) > 0)
            {
                MessageBox.Show("Thêm NCC Thanh Cong!");
                return true;
            }
            else return false;
        }

        public bool Suancc(Nhacungcapclass m_ncc)
        {
            SqlCommand cmd = new SqlCommand("Update nhacungcap set tenncc = @tenncc, dienthoai = @dienthoai, diachi = @diachi where mancc = @mancc");
            cmd.Parameters.Add("mancc", SqlDbType.VarChar).Value = m_ncc.Mancc;
            cmd.Parameters.Add("tenncc", SqlDbType.NVarChar).Value = m_ncc.Tenncc;
            cmd.Parameters.Add("dienthoai", SqlDbType.Float).Value = m_ncc.Dienthoai;
            cmd.Parameters.Add("diachi", SqlDbType.Text).Value = m_ncc.Diachi;
            

            if (m_nhacungcap.ExecuteNonQuery(cmd) > 0)
            {
                MessageBox.Show("Sửa NCC thành công!");
                return true;
            }
            else return false;
        }
    }
}
